package leetcode;

public class Day23 {
    public int getMaxLen(int[] nums) {
        int n=nums.length;
        int[] g=new int[n+1];
        int[] j=new int[n+1];
        for(int i=1;i<=n;i++){
            if(nums[i-1]<0){
                g[i]=j[i-1]==0?0:j[i-1]+1;
                j[i]=g[i-1]+1;
            }else if(nums[i-1]>0){
                g[i]=g[i-1]+1;
                j[i]=j[i-1]==0?0:j[i-1]+1;
            }
        }
        int max=Integer.MIN_VALUE;
        for(int i=1;i<=n;i++){
            if(g[i]>max){
                max=g[i];
            }
        }
        return max;
    }
    public int numberOfArithmeticSlices(int[] nums) {
        int n=nums.length;
        int[] dp=new int[n];
        int sum=0;
        for(int i=2;i<n;i++){
            if(nums[i-1]*2==nums[i-2]+nums[i]){
                dp[i]=dp[i-1]+1;//以i位置为结尾的等差数列子数组和
            }else{
                dp[i]=0;
            }
            sum+=dp[i];
        }
        return sum;
    }

}
